home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6001 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: ix.netcom.com!netnews
  2. From: judgemi@ix.netcom.com(Michael Judge )
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: new and 2-D Arrays?
  5. Date: 7 Feb 1996 19:08:48 GMT
  6. Organization: Netcom
  7. Message-ID: <4fatc0$8lg@cloner4.netcom.com>
  8. References: <4famh5$chp@canyon.sr.hp.com>
  9. NNTP-Posting-Host: bos-ma8-25.ix.netcom.com
  10. X-NETCOM-Date: Wed Feb 07 11:08:48 AM PST 1996
  11.  
  12. In <4famh5$chp@canyon.sr.hp.com> rolando@sr.hp.com (Rolando Ampuero)
  13. writes: 
  14. >
  15. >Hello, This question was problably asked already, but as a newbie in
  16. the
  17. >world of C++, this is one place I found that relates to this subject.
  18. >According to several manuals that I have read I can declare a two
  19. dimensional
  20. >array in this manner 
  21. >
  22. >int *myptr = new int [8][8];
  23. >
  24. >but when I tried to compile I get errors, is this not the correct way
  25. to do 
  26. >it? Are the books wrong? (One of the books is Deitel pg 415).
  27. >
  28. >If there is a FAQ site where I can go to, please let me know.
  29. >
  30. >--
  31.  
  32. I cant exactly tell you why the compile error, but I can tell you that
  33. even if it compiled, you wouldn't be able to index it properly. how can
  34. the compiler know how to offset myptr[3][4].  It would have to remember
  35. to multiply 3*8 and add 4 to get to the proper address.  Unless you
  36. declare this myptr[8][4], at compile time It cant prepare the proper
  37. constants( in this case 8) to be multiplied to the first index.
  38.  
  39. MJ
  40.  
  41.